package com.wish.wishsystem_management.controller;

import com.wish.wishsystem_management.entity.SysUser;
import com.wish.wishsystem_management.service.ISysUserService;

import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.MessageDigest;
@Slf4j
@RestController
public class SysRegisterController {
@Autowired
ISysUserService iSysUserService;
    MessageDigest digest;

//
    @Resource
    PasswordEncoder passwordEncoder2;

    /**
     * 注册
     */
    @RequestMapping(value = "/sys/register")
    public String register(@RequestBody SysUser register, HttpServletResponse response)throws IOException {

        System.out.println("999998888"+register);
        String mobile = register.getMobile();
        SysUser sysUserEntity = iSysUserService.getSysUserByMobile(mobile);
//
//        if(sysUserEntity != null){
//            return  "该手机号码已经存在！";
//        }


//        ResponseDto<String> responseDto  = smsValidateService.checkSMSCode(register.getMobile(), register.getMobileCode(), register.getType());
//        if (!responseDto.getResult()) {
//            return R.error(responseDto.getErrorMessage());
//        }

        System.out.println("用户加密前的密码password"+register.getPassword());


//        sha256加密   sha256加密   sha256加密   sha256加密   sha256加密  st

//
//        try {
//            digest = MessageDigest.getInstance("SHA-256");
//            byte[] hash = digest.digest(register.getPassword().getBytes("UTF-8"));
//            String output = Hex.encodeHexString(hash);
//
//
//            System.out.println("用户加密后的密码password"+output);
//            register.setPassword(output);
//        } catch (NoSuchAlgorithmException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }catch (UnsupportedEncodingException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
//
//

//        sha256加密   sha256加密   sha256加密   sha256加密   sha256加密  ed
        //        md5加密  md5加密md5加密md5加密不vmd5加密md5加密md5加密md5加密md5加密md5加密   st


//        register.setPassword(MD5Utils.md5(register.getPassword()));



        register.setPassword(passwordEncoder2.encode(register.getPassword()));






        System.out.println("用户outh2加密后的密码password"+register.getPassword());








           log.info("我是888888877777");




        //        md5加密  md5加密md5加密md5加密不vmd5加密md5加密md5加密md5加密md5加密md5加密   ed





        iSysUserService.register(register);

//
//        R r = sysUserTokenService.createToken(register.getUserId());
//        WebUtils.setCookie(response, "token", (String)r.get("token"), (int)r.get("expire"));
//
//        //apartmentOperatorType 注册人类型  0 个人职业房东 1 公司化公寓
//        return r.put("userId", register.getUserId()).put("contactMember", register.getContactMember()).put("apartmentOperatorType", register.getApartmentOperatorType());

return "注册成功";

    }




}
